package org.hk.kg.utils;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class StringUtils {
	public static boolean isEmpty(String str)
	{
		return null == str || "".equals(str);
	}
	
	public static String field2Getter(String feild)
	{
		return "get" + (char)(feild.charAt(0) - 32) + feild.substring(1);
	}
	public static Map parseParams(Map params)
	{
		Map<String,Object> rlt = new HashMap();
		for(Iterator<Entry> entryIterator=params.entrySet().iterator();entryIterator.hasNext();)
		{
			Entry entry = entryIterator.next();
			Object entryValue = entry.getValue();
			if(entryValue instanceof List)
			{
				List entryList = (List) entryValue;
				rlt.put(""+entry.getKey(), entryList.isEmpty()?"":entryList.get(0));
			}
			else
			{
				rlt.put(""+entry.getKey(), entryValue);
			}
		}
		return rlt;
	}
	
	public static final <T,M>Object decodeEmpty(M str,T rlt)
	{
		if(null == str)
		{
			return rlt;
		}
		
		
		if(isEmpty(""+str) || "NULL".equalsIgnoreCase(""+str))
		{
			return rlt;
		}
		return str;
	}
}
